package com.huobao.yunying.activitys.muyingquan;

import java.util.ArrayList;
import java.util.List;

import org.simple.eventbus.EventBus;
import org.w3c.dom.Text;
import org.xutils.view.annotation.ViewInject;

import com.huobao.yunying.adapters.ViewPagerAdapter;
import com.huobao.yunying.base.HuobaoBaseActivity;
import com.huobao.zhangying.R;

import android.app.LocalActivityManager;
import android.content.Intent;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;

/**
 * 圈子详情
 * 
 * @author Administrator
 *
 */
public class Act_Quanzi_Detail extends HuobaoBaseActivity
		implements OnCheckedChangeListener, OnPageChangeListener, OnClickListener {
	@ViewInject(R.id.radiogroup)
	private RadioGroup rg;
	@ViewInject(R.id.view_1)
	private ViewPager viewPager;
	private ViewPagerAdapter adapter;
	private List<View> views;
	private LocalActivityManager manager = null;
	@ViewInject(R.id.rb_1)
	private RadioButton rb_1;
	@ViewInject(R.id.rb_2)
	private RadioButton rb_2;
	@ViewInject(R.id.btn_back)
	private TextView btn_back;
	@ViewInject(R.id.fatie)
	private ImageView btn_fatie;
	//圈子编号
	private String id;

	@Override
	protected int getContentView() {
		return R.layout.layout_quanzi_detail;
	}

	@Override
	protected String getTitleText() {
		return null;
	}

	@Override
	protected void init() {
		id = getIntent().getStringExtra("id");
		mAbTitleBar.setVisibility(View.GONE);
		manager = new LocalActivityManager(this, true);
		manager.dispatchCreate(savedInstanceState);
		views = new ArrayList<View>();
		Intent i1 = new Intent(this, Act_QuanziDetail_All.class);
		i1.putExtra("id", id);
		views.add(getView("A", i1));
		Intent i2 = new Intent(this, Act_QuanziDetail_Jinghua.class);
		i2.putExtra("id", id);
		views.add(getView("B", i2));
		adapter = new ViewPagerAdapter(views);  
		viewPager.setAdapter(adapter);   
		
		rg.setOnCheckedChangeListener(this);
		viewPager.setOnPageChangeListener(this);
		btn_back.setOnClickListener(this);
		btn_fatie.setOnClickListener(this);
	}

	private View getView(String id, Intent intent) {
		return manager.startActivity(id, intent).getDecorView();
	}

	@Override
	public void onPageScrollStateChanged(int arg0) {
	}

	@Override
	public void onPageScrolled(int arg0, float arg1, int arg2) {
	}

	@Override
	public void onPageSelected(int arg0) {
		switch (arg0) {
		case 0:
			rb_1.setChecked(true);
			break;
		case 1:
			rb_2.setChecked(true);
			break;
		}
		EventBus.getDefault().post("", "scroll");
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_back:
			finish();
			break;
		case R.id.fatie:
			Intent intent=new Intent(Act_Quanzi_Detail.this,Act_Quanzi_Fatie.class);
			intent.putExtra("id", id);
            startActivity(intent); 
			break;
		}
	}

	@Override
	public void onCheckedChanged(RadioGroup group, int checkedId) {
		switch (checkedId) {
		case R.id.rb_1:
			viewPager.setCurrentItem(0);
			break;
		case R.id.rb_2:
			viewPager.setCurrentItem(1);
			break;
		}
		EventBus.getDefault().post("", "scroll");
	}
}
